package com.ch.web.entity.user;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ch.web.requestDto.xyUser.RegisterFormDto;
import lombok.Data;
import lombok.ToString;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.Date;

/**
 * @author chenHao
 * @email 1429542285@qq.com
 * @date 2022-04-27 22:59:18
 */
@ToString
@Data
@TableName("xy_user")
public class XyUserEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 用户主键
     */
    @TableId(type = IdType.AUTO)
    private Long userId;
    /**
     * 用户昵称
     */
    private String userNick;
    /**
     * 用户账号
     */
    private String userName;
    /**
     * 用户密码
     */
    private String userPassword;
    /**
     * 用户电话
     */
    private String userTel;
    /**
     * 用户邮箱
     */
    private String userEmail;
    /**
     * 用户身份证
     */
    private String userIdCard;
    /**
     * 用户年龄
     */
    private Integer userAge;
    /**
     * 用户地址
     */
    private String userAddress;
    /**
     * 用户性别
     */
    private String userSex;

    /**
     * 用户状态(0代表禁用,1正常,2违法被封)
     */
    private int userStatus;
    private Date userCreateTime;
    private Date userWfTime;
    /**
     * 1.在线中
     * 0.离线中
     */
    private Integer userOnline;
    private String userAva;


    public static XyUserEntity createUserByRegisterDto(RegisterFormDto dto){
        XyUserEntity xyUserEntity = new XyUserEntity();
        xyUserEntity.setUserEmail(dto.getUserEmail());
        xyUserEntity.setUserNick(dto.getUserNick());
        xyUserEntity.setUserName(dto.getUserName());
        xyUserEntity.setUserPassword(dto.getUserPassword());
        xyUserEntity.setUserAge(Integer.valueOf(dto.getUserAge()));
        xyUserEntity.setUserSex(dto.getUserSex());
        if (!StringUtils.isEmpty(dto.getUserAva())){
            xyUserEntity.setUserAva(dto.getUserAva());
        }
        return xyUserEntity;

    }
}
